package com.project.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.project.dao.IMenuRelationDao;
import com.project.dao.bean.MenuRelation;
import com.project.webapp.form.backend.basic.MenuForm;

public class MenuRelationDaoImpl extends BaseDaoImpl implements IMenuRelationDao {

    @Override
    public void save(MenuRelation menuRelation) throws Exception {
        this.getSqlMapClient().insert("saveMenuRelation", menuRelation);
    }

    @Override
    public List<String> getAncestorIdByDescendantId(String descendantId) throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        map.put("descendantId", descendantId);
        List<String> list = this.getSqlMapClient().queryForList("getAncestorIdByDescendantId", map);
        return list;
    }

    @Override
    public boolean isHaveSubMenu(MenuForm menuForm) throws Exception {
        Integer count = (Integer) this.getSqlMapClient().queryForObject("isHaveSubMenu", menuForm);
        if (count > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void delete(MenuForm menuForm) throws Exception {
        this.getSqlMapClient().update("deleteMenuRelation", menuForm);
    }

}
